package com.gxy.learn.design.model.behaviour.memento.black_box;

import lombok.extern.slf4j.Slf4j;

/**
 * @description:   发起人角色
 * @author: gaoxueyong
 * @Date: 2022/11/9 09:24
 */
@Slf4j
public class GameRole {
//    生命力
    private int vit;
//    防御力
    private int atk;
//    攻击力
    private int def;

    /**
     * 初始化角色
     * @Author gaoxueyong
     * @Date 9:27 上午 2022/11/9
     * @Param []
     * @return void
     **/
    public void initState(){
        this.vit = 100;
        this.atk = 100;
        this.def = 100;
    }
    /**
     * 战斗方法
     * @Author gaoxueyong
     * @Date 9:28 上午 2022/11/9
     * @Param []
     * @return void
     **/
    public void fight(){
        this.vit = 0;
        this.atk = 0;
        this.def = 0;
    }

    /**
     * 备份状态
     * @Author gaoxueyong
     * @Date 9:31 上午 2022/11/9
     * @Param []
     * @return com.gxy.learn.design.model.behaviour.memento.white_box.RoleStateMemento
     **/
    public RoleStateMemento saveState(){
        return new RoleStateMemento(this.vit,this.atk,this.def);
    }

    /**
     * 恢复状态
     * @Author gaoxueyong
     * @Date 9:31 上午 2022/11/9
     * @Param [stateMemento]
     * @return void
     **/
    public void recoverState(Memento memento){
        RoleStateMemento stateMemento = (RoleStateMemento) memento;
        this.vit = stateMemento.getVit();
        this.atk = stateMemento.getAtk();
        this.def = stateMemento.getDef();
    }
    /**
     * 状态打印
     * @Author gaoxueyong
     * @Date 9:34 上午 2022/11/9
     * @Param []
     * @return void
     **/
    public void displayState(){
        log.info("生命力：{},防御力：{},攻击力：{}",this.vit,this.atk,this.def);
    }

    public int getVit() {
        return vit;
    }

    public void setVit(int vit) {
        this.vit = vit;
    }

    public int getAtk() {
        return atk;
    }

    public void setAtk(int atk) {
        this.atk = atk;
    }

    public int getDef() {
        return def;
    }

    public void setDef(int def) {
        this.def = def;
    }


    public static class RoleStateMemento implements Memento{
        //    生命力
        private int vit;
        //    防御力
        private int atk;
        //    攻击力
        private int def;

        public RoleStateMemento() {
        }

        public RoleStateMemento(int vit, int atk, int def) {
            this.vit = vit;
            this.atk = atk;
            this.def = def;
        }

        public int getVit() {
            return vit;
        }

        public void setVit(int vit) {
            this.vit = vit;
        }

        public int getAtk() {
            return atk;
        }

        public void setAtk(int atk) {
            this.atk = atk;
        }

        public int getDef() {
            return def;
        }

        public void setDef(int def) {
            this.def = def;
        }
    }
}
